from django_filters.rest_framework import FilterSet
from django_filters.filters import *
from .models import *


class UserFilterSet(FilterSet):
    name = CharFilter(lookup_expr="contains")
    username = CharFilter(lookup_expr="contains")
    email = CharFilter(lookup_expr="contains")
    mobile = CharFilter(lookup_expr="contains")
    start_time = DateFilter(
        field_name="create_time", lookup_expr="gte", label="开始日期"
    )
    end_time = DateFilter(field_name="create_time", lookup_expr="lt", label="结束日期")

    class Meta:
        model = User
        fields = [
            "name",
            "username",
            "email",
            "mobile",
            "start_time",
            "end_time",
            "dept",
        ]


class UserNotificationFilterSet(FilterSet):
    title = CharFilter(lookup_expr="contains")
    content = CharFilter(lookup_expr="contains")
    start_time = DateFilter(
        field_name="create_time", lookup_expr="gte", label="开始日期"
    )
    end_time = DateFilter(field_name="create_time", lookup_expr="lt", label="结束日期")

    class Meta:
        model = UserNotification
        fields = [
            "title",
            "content",
            "type",
            "is_read",
            "start_time",
            "end_time",
            "user",
        ]
